package com.ruoyi.web.controller.demo.controller;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AntMerchantExpandIndirectZftorderQueryRequest;
import com.alipay.api.response.AntMerchantExpandIndirectZftorderQueryResponse;

public class AntMerchantExpandIndirectZftorderQuery {
    public static void main(String[] args) throws AlipayApiException {
        String appCertPath = "/Users/mac/Documents/WORK/场景/直付通11/appCertPublicKey_2021003196668931.crt";
        // 支付宝公钥证书路径
        String alipayCertPath = "/Users/mac/Documents/WORK/场景/直付通11/alipayCertPublicKey_RSA2.crt";
        // 支付宝根证书路径
        String alipayRootCertPath = "/Users/mac/Documents/WORK/场景/直付通11/alipayRootCert.crt";

        // 支付宝网关
        String serverUrl = "https://openapi.alipay.com/gateway.do";
        // 应用APPID
        String appId = "2021003196668931";
        // 初始化SDK
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        //设置网关地址
        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
        //设置应用Id
        certAlipayRequest.setAppId(appId);
        //设置应用私钥
        certAlipayRequest.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCYjCsmZsld84YkTStL/AATrGzCmSLb6J4FZGV4eYSZWdGhsPDf3XEzCMTL/g3WvDNIISGiVek2NYXGKqy6VMdKHoS+miypmJVZ3EkgPwj/0hJWeyrKvWFn1nIUeW8u7mnJ7KJl51Opaj/+RUtkGWHKxOrBCY5KT2q7hiUTszuLCt23muU8dF9nxL9Kc+x6NgtPhj/oGdJNgQZMdjBqvshZ06oVoHcWDzK+zJJmft4YI+Km1+Uvcyk5ZtPDFXaqeFuSCUPBdRHq9AdoUG/CW1Xy0xVcICAZnI0SzuhKH9eEhyuLQ8yKHp8kajzXTxCUgKU5qI8wQmI2YiupVdQ+HqhDAgMBAAECggEAUcxnnvHi7HQW7ARNQ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BPTtLD+96HpLvNgiCtGTi+N0i0xa3mxyrOJwIvnKawCrHjO44wrtW59XLD6Ns8J2VxW9BYuGNFJ7SU+PXJ5nVNhdC9USLs9B7agLOJ9mOmNWCRuW1Jvrs=");
        //设置请求格式，固定值json
        certAlipayRequest.setFormat("json");
        //设置字符集
        certAlipayRequest.setCharset("UTF-8");
        //设置签名类型
        certAlipayRequest.setSignType("RSA2");
        //设置应用公钥证书路径
        certAlipayRequest.setCertPath(appCertPath);
        //设置支付宝公钥证书路径
        certAlipayRequest.setAlipayPublicCertPath(alipayCertPath);
        //设置支付宝根证书路径
        certAlipayRequest.setRootCertPath(alipayRootCertPath);
        //构造client
        AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
        AntMerchantExpandIndirectZftorderQueryRequest request = new AntMerchantExpandIndirectZftorderQueryRequest();
        request.setBizContent("{" +
                "  \"order_id\":\"2024032700502000000012668539\"" +
                "}");
        AntMerchantExpandIndirectZftorderQueryResponse response = alipayClient.certificateExecute(request);
        if(response.isSuccess()){
            System.out.println("调用成功"+ JSON.toJSONString(response));
        } else {
            System.out.println("调用失败");
        }
    }
}
